import execjs, requests,js2py


# print(execjs.get().name)
# ctx = execjs.compile('''
#     function add(x,y)
#     {
#         return x+y
#     }
# ''')
#
# print(ctx.call('add',1,2))

def down(url):
    # headers = {
    #     ''
    # }
    data ={
        'time_interval': '',
        'tag': '',
        'tag_type': '',
        'province': '',
        'lunci': '',
        'page': 1,
        'num': 20,
        'unionid': ''
    }
    res = requests.post(url,data=data ) # ,headers=headers)
    return res


if __name__ == '__main__':
    url = 'https://vipapi.qimingpian.cn/DataList/productListVip'
    encrypt_data = down(url).json()['encrypt_data']
    print(type(encrypt_data))

    with open('js/qmkj.js', 'r', encoding='utf-8') as f:
        jscode = f.read()
#
#     print(encrypt_data)
#     # print(jscode)
#     ctx = execjs.compile(jscode).call('s', encrypt_data)
#     print('1')

# with PyV8.JSContext() as ctx:
#     ctx.eval(jscode)
#     print(ctx.locals.add(encrypt_data))

add = js2py.eval_js(jscode)
print(add)